import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Random;


public class TestMemoryCopy {
	/**
	 * @param args
	 */
	public TestMemoryCopy() {

	}
	public static long testIo(int size,int n) throws IOException
	{
		byte[] buf = new byte[size];
		long t1 = System.nanoTime();
		for (int i=0;i<n;i++)
		{
			ByteArrayInputStream in = new ByteArrayInputStream(buf);
			ByteArrayOutputStream outp = new ByteArrayOutputStream();
			byte[] b =new byte[n];
			in.read(b);
			outp.write(b);
		}
		long t2 = System.nanoTime();
		return (t2-t1)/n;
	}
	public static long testNio(int size,int n) throws IOException
	{
		byte[] buf = new byte[size];
		long t1 = System.nanoTime();
		for (int i=0;i<n;i++)
		{
       ByteBuffer bb = ByteBuffer.wrap(buf);
       ByteBuffer bb2 = ByteBuffer.wrap(bb.array());
		}
		long t2 = System.nanoTime();
		return (t2-t1)/n;
	}
	public static long testSystem(int size,int n) throws IOException
	{
		byte[] buf = new byte[size];
		byte[] buf2 = new byte[size];
		long t1 = System.nanoTime();
		  for (int j =0;j<n;j++)
		  {
      System.arraycopy(buf, 0, buf2, 0, n);
		  }
		  long t2 = System.nanoTime();
			return (t2-t1)/n;
	}
	public static long testDummy(int size,int n) throws IOException
	{
		byte[] buf = new byte[size];
		byte[] buf2 = new byte[size];
		long t1 = System.nanoTime();
		for (int j=0;j<n;j++)
		{
      for (int i=0;i<size;i++)
		{
    	  buf2[i]=buf[i];
		}
		}
		long t2 = System.nanoTime();
		return (t2-t1)/n;
		}
}
